<template>
    <div class="site">
        <div class="site-body">
            <div class="row f f-ac">
                <div class="row-title">标题检索：</div>
                <div class="f-1">
                    <el-input v-model="queryForm.search" placeholder="输入关键词" size="small" clearable style="width: 653px"
                        @change="search" />
                </div>
            </div>
            <div class="row f f-ac">
                <div class="row-title">场馆类型：</div>
                <div v-for="(i, k) in typeList" :key="k" class="type-item" :class="{ checked: queryForm.type == i.id }"
                    @click="handleType(i)">
                    {{ i.name || "-" }}
                </div>
            </div>
            <div class="row f f-ac">
                <div class="row-title">区域：</div>
                <div v-for="(i, k) in areaList" :key="k" class="type-item" :class="{ checked: queryForm.area == i }"
                    @click="handleArea(i)">
                    {{ i || "-" }}
                </div>
                <div class="row-title">自定义：</div>
                <div>
                    <el-date-picker v-model="queryForm.startTime" type="date" placeholder="选择开始日期" style="width: 160px"
                        :picker-options="startPicker" @change="handleStart" value-format="yyyy-MM-dd" />
                    -
                    <el-date-picker v-model="queryForm.endTime" type="date" placeholder="选择结束日期" style="width: 160px"
                        :picker-options="endPicker" @change="handleEnd" value-format="yyyy-MM-dd" />
                </div>
            </div>
            <div class="site-box f f-js f-w">
                <div v-for="(i, k) in dataList" :key="k" class="site-item" @click="handleDetail(i)">
                    <img :src="baseUrl+i.image" />
                    <div class="item-title line-1">{{ i.title || "-" }}</div>
                    <div class="item-address f f-ac f-jb">
                        <div class="f-1 line-1">地点：{{ i.address || "-" }}</div>
                    </div>
                    <div class="item-address f f-ac f-jb">
                        <div class="f-1 line-1">时间：{{ i.createtime || "-" }}</div>
                    </div>
                </div>
            </div>
            <Page-tool :size="queryForm.pageSize" :page="queryForm.currentPage" :total="total"
                @change-page="changePage" />
        </div>
    </div>
</template>

<script>
    import {
        venueCategory,
        venueList,
        venueCity
    } from "@/utils/order/index.js";
    export default {
        data() {
            return {
                baseUrl: process.env.VUE_APP_BASE_API,
                queryForm: {
                    search: "", // 搜索关键词
                    type: "", // 场馆类型
                    area: "全部", // 区域
                    startTime: "", // 开始时间
                    endTime: "", // 结束时间
                    pageSize: 12, // 条数
                    currentPage: 1, // 页数
                },
                total: 0, // 总数
                typeList: [],
                areaList: [],
                startPicker: {
                    // 开始时间限制
                    disabledDate: (time) => {
                        let endTime = this.queryForm.endTime;
                        if (endTime) return time.getTime() > new Date(endTime).getTime();
                    },
                },
                endPicker: {
                    // 结束时间限制
                    disabledDate: (time) => {
                        let startTime = this.queryForm.startTime;
                        if (startTime) return time.getTime() < new Date(startTime).getTime();
                    },
                },
                dataList: [],
            };
        },

        mounted() {},
        created() {
            this.queryForm.search = this.$route.query.search ? this.$route.query.search : ''
            this.getTypeList();
            this.getAreaList();
            this.getList();
        },
        methods: {
            // 搜索
            search() {
                this.getList();
            },
            handleStart(v) {
                this.queryForm.startTime = v
                this.getList();
            },
            handleEnd(v) {
                this.queryForm.endTime = v
                this.getList();
            },
            // 获取活动列表
            getList() {
                this.loading = true;
                let that = this
                let data = {
                    venue_category_id: that.queryForm.type,
                    title: that.queryForm.search,
                    type: '',
                    page: that.queryForm.currentPage,
                    limit: 12,
                    starttime: that.queryForm.startTime,
                    type_time: '',
                    endtime: that.queryForm.endTime,
                    recommend: '',
                    city: that.queryForm.area != '全部' ? that.queryForm.area : ''
                }
                venueList(data).then((response) => {
                    if (response.code == 200) {
                        that.dataList = response.data.list
                        that.loading = false;
                        that.total = response.data.count
                    }
                });
            },
            // 获取区域分类
            getAreaList() {
                this.loading = true;
                let that = this
                venueCity().then((response) => {
                    if (response.data.code != 1) {
                        response.data.unshift("全部");
                        that.areaList = response.data
                    }

                    that.loading = false;
                });
            },
            // 获取场馆分类
            getTypeList() {
                this.loading = true;
                let that = this
                venueCategory().then((response) => {
                    response.data.unshift({
                        id: "",
                        name: "全部",
                    });
                    that.typeList = response.data
                    that.loading = false;
                });
            },
            // 切换类型
            handleType(v) {
                this.queryForm.currentPage = 1;
                this.queryForm.type = v.id;
                this.getList();
            },
            // 切换区域
            handleArea(v) {
                this.queryForm.area = v;
                this.getList();
            },
            // 查看详情
            handleDetail(v) {
                this.$router.push({
                    path: "/reservedSite/details",
                    query: {
                        id: v.id,
                    },
                });
            },
            // 切换页数
            changePage(page) {
                this.queryForm.currentPage = page;
                this.getList();
            }
        },
    };
</script>

<style lang="scss" scoped>
    .site {
        width: 100%;

        &-body {
            width: 1200px;
            min-height: 200px;
            margin: auto;

            .row {
                height: 36px;
                width: 100%;
                margin-bottom: 15px;

                &:first-child {
                    margin-top: 40px;
                }

                &-title {
                    width: 90px;
                }

                .type-item {
                    display: inline-block;
                    min-width: 70px;
                    text-align: center;
                    height: 27px;
                    line-height: 27px;
                    color: #333;
                    background-color: #f4f4f4;
                    margin-right: 10px;
                    font-size: 12px;
                    border-radius: 3px;
                    padding: 0 10px;
                    box-sizing: border-box;

                    &:hover {
                        user-select: none;
                        cursor: pointer;
                    }
                }

                .checked {
                    color: #fff;
                    background-color: #193980;
                }
            }

            .site-box {
                width: 100%;
                padding-top: 30px;
                border-top: 1px solid #d9d9d9;

                .site-item {
                    margin-right: 26px;
                    margin-bottom: 30px;
                    width: 280px;
                    height: 299px;
                    border-radius: 5px;
                    background-color: #fff;
                    overflow: hidden;
                    box-shadow: 0 1px 10px 0 rgba(217, 217, 217, 0.3);
                    transition: all 0.5s;

                    &:hover {
                        cursor: pointer;
                        box-shadow: 0 1px 10px 0 rgba(130, 130, 130, 0.3);
                    }

                    &:nth-child(4n) {
                        margin-right: 0;
                    }

                    img {
                        width: 100%;
                        height: 212px;
                    }

                    .item-title {
                        height: 23px;
                        color: #313131;
                        font-size: 14px;
                        line-height: 23px;
                        margin: 8px 10px;
                    }

                    .item-address {
                        color: #909090;
                        font-size: 12px;
                        margin: 4px 10px;
                    }
                }
            }
        }
    }

    ::v-deep .el-input__inner {
        background-color: #f7f8fa;
        border-radius: 5px;
        border: none;
    }
</style>